package cn.wmw.xyy.web.controller;

import cn.wmw.result.JsonResult;
import cn.wmw.xyy.dto.SmsCodeDto;
import cn.wmw.xyy.service.IVerifyCodeService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService iVerifyCodeService;

    /**
     * 获取图形验证码
     */
    @GetMapping("/imageCode/{imageCodeKey}")
    public JsonResult graph(@PathVariable String imageCodeKey) {
        String base64 =  iVerifyCodeService.graph(imageCodeKey);
        return JsonResult.success(base64);
    }
    /**
     * 获取图形验证码
     */
    @PostMapping("/sendSmsCode")
    public JsonResult smsCode(@RequestBody SmsCodeDto dto) {
        iVerifyCodeService.smsCode(dto);
        return JsonResult.success();

    }

    /**
     * 获取专属链接code码..4位
     * @return
     */
    @RequestMapping(value = "/linkCode",method = RequestMethod.GET)
    public JsonResult linkCode(){
        String linkCode = iVerifyCodeService.getLinkCode();
        return JsonResult.success(linkCode);

    }


    /**
     * 获取专属链接二维码
     * @return
     */
    @RequestMapping(value = "/QRCode",method = RequestMethod.GET)
    public JsonResult QRCode(){
        JsonResult jsonResult = linkCode();
        String code = JSONObject.parseObject(JSONObject.toJSONString(jsonResult.getData()), String.class);
        JsonResult jsonResult1 = iVerifyCodeService.QRCode(code);
        String QRCode = JSONObject.parseObject(JSONObject.toJSONString(jsonResult1.getData()), String.class);
        return JsonResult.success(QRCode);

    }


}
